import pydot
import networkx as nx
  #myfolder='c:/hongwufiles/igem/'
myfolder='d:/human/sqldata/'
G=pydot.Dot()
GN=nx.MultiDiGraph()
f1=open(myfolder+'met_link.txt', 'r')
for s in f1.readlines():
    a=s.split('\t')
#    e=pydot.Edge(a[1],a[2],arrowhead="none",color="white")
#            e.set_arrowsize("0.2")
#    G.add_edge(e)
    GN.add_edge(a[1],a[2])
f1.close()
UG=GN.to_undirected()
wcs=nx.connected_component_subgraphs(UG)
#G=nx.to_pydot(wcs[0])
for edge in wcs[0].edges():
    e=pydot.Edge(list(edge)) #sth wrong here
    G.add_edge(e)
f2=open(myfolder+'comdegp.txt', 'r')
for s in f2.readlines():
    a=s.split('\t')
    if a[0] in wcs[0]:
      hw=str(0.02*int(a[2]))
      n=pydot.Node(a[0],label=" ",fixedsize="1", height=hw,width=hw,tooltip=a[0],color=a[1],style="filled")
#            n.set_color("transparent")
#            n.set_fillcolor("red") #color is used if fillcolor not defined
    G.add_node(n)
f2.close()
G.set_bgcolor("white")
G.set_concentrate("true")
#G.write(myfolder+'hunet.dot', prog="dot", format='raw')
G=pydot.graph_from_dot_file(myfolder+'hunet.dot')
G.write(myfolder+'hunet.svg', prog="None",format="svg")
#G.write(myfolder+'hunet.svg', prog="dot",format="svg")

